package Month5;

import java.io.*;

public class A20250506FileTest
{
    public static void main(String[] args) throws IOException
    {

        File from = new File("myfile");
        File to = new File("myfileCopy");
        
        copyDir(from,to);

    }

    //拷贝文件夹
    private static void copyDir(File from, File to) throws IOException
    {
        to.mkdirs();
        File[] files = from.listFiles();
        for(File temp :files)
        {
            if(temp.isFile())
            {
                FileInputStream fis = new FileInputStream(temp);
                FileOutputStream fos = new FileOutputStream(new File(to, temp.getName()));
                byte[] bs = new byte[1024];
                int len;
                while((len = fis.read(bs)) != -1)
                {
                    fos.write(bs,0,len);
                }
            }
            else
            {
                copyDir(temp,new File(to,temp.getName()));
            }
        }
    }
}
